<?php
/**
 * Created by PhpStorm.
 * User: fangwei
 * Date: 2019-08-21
 * Time: 17:01
 */

namespace App\Http\Requests\Admin;


use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Config;
use Illuminate\Validation\Rule;

class ProductInputDTO extends FormRequest
{
    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        return [
            'name' => 'required|max:200',
            'cover' => 'max:200',
            'year' => [
                'required',
                Rule::in(array_keys(Config::get('constant.year')))
            ],
            'product_model' => [
                'required',
                Rule::in(array_keys(Config::get('constant.product_model')))
            ],
            'item' => 'array',
            'item.id' => 'integer',
            'item.amount' => 'integer',
        ];
    }

    public function messages()
    {
        return [
            'name.required' => '标题必须填写',
            'name.max' => '标题不能超过200个字符',
            'cover.max' => '封面图片不能超过200个字符',
            'year.required' => '年份必须选择',
            'year.in' => '年份选择错误，不存在的年份',
            'product_model.required' => '产品类型必须选择',
            'product_model.in' => '产品类型选择错误，不存在的年份',
        ];
    }
}